package com.wondersgroup.fjzlpt.tbxt.controller.rest.jc;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.tbxt.beans.req.jcYb.QueryOneReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.req.jcYb.SaveReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.BaseRespBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.jcYb.QueryOneRespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.tbxt.service.inter.jc.JcYbService;

@RestController
@RequestMapping("/jcyb")
@Api(value = "基层月报标准接口", tags = "JcYbRestController", description = "基层月报API")
public class JcYbRestController {

	@Autowired
	private JcYbService jcYbService;

	/**
	 * 保存或更新
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "保存或更新", notes = "保存或更新基层月报信息", response = BaseRespBean.class)
	@RequestMapping(value = "/save",method = RequestMethod.POST)
	public JSONObject save(HttpServletRequest request, SaveReqBean saveBean){
		Map map = RequestUtils.GetParameterMap(request);
		map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
		map.put("JGLB", QuickPrincipalUtils.getJglbdm(request));
		map.put("XZQH", QuickPrincipalUtils.getXzqhdm(request));
		map.put("JGMC", QuickPrincipalUtils.getUserinfoByKey(request,"YLJGMC"));
		return jcYbService.save(map);
	}
	
	/**
	 * 根据机构id和填报时间，查询某机构填报记录
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "查询", notes = "查询基层月报填报信息", response = QueryOneRespBean.class)
	@RequestMapping(value = "/queryOne",method = RequestMethod.POST)
	public JSONObject queryOne(HttpServletRequest request, QueryOneReqBean queryOneReqBean){
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(StringUtils.isEmpty(map.get("YLJGID"))){
			map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
		}
		map.put("YLJGMC",(String)QuickPrincipalUtils.getUserinfoByKey(request, "YLJGMC"));
		return jcYbService.queryOne(map);
	}
}
